Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat(nuxt): prefetch middleware/layouts + await layout loading #10155

Merged
merged 4 commits into from
Jan 19, 2023

Conversation

atinux
Copy link
Member

@atinux atinux commented Jan 18, 2023

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Hooked into link:prefetch to prefetch the layouts and middleware πŸš€

I also forced thge prefetching of layout on route navigation (not needed to depend on Suspense) like I did on Nuxt 2, this way we don't change the page until the layout if fully resolved.

Before (slow 3g):

CleanShot_2023-01-18_at_16.48.00.mp4

After (slow 3g):

CleanShot_2023-01-18_at_16.54.31.mp4

@atinux atinux requested a review from danielroe January 18, 2023 16:32
@codesandbox
Copy link

codesandbox bot commented Jan 18, 2023

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

packages/nuxt/src/core/nuxt.ts Outdated Show resolved Hide resolved
Comment on lines 36 to 38
if (layout && typeof layouts[layout] === 'function') {
layouts[layout]()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, this is only imported in <NuxtLayout> which means layout files are not bundled unless a layout is actually used. I wonder if we can move this elsewhere (maybe first use of <NuxtLayout> triggers hook registration?)

If not, I think it's a reasonable trade-off given the very nice improvement in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean importing the build/layouts will make the creation of the chunks?

i think it’s fine if they are always created IMO

we could also check if we have layouts defined but NuxtLayout is never used (I experienced this, layouts but forgot to use the NuxtLayout component in app.vue and got no warnings)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a nice idea! Only scenario I can think of where it would be a pain is when you have a theme that provides layouts but the end project doesn't want to use any of them. Or if <NuxtLayout> is only being used within a page and only on some of the site. (But still I think the warning would be fine.)

(I don't think it has to be in this PR though.)

@vercel vercel bot temporarily deployed to Preview January 19, 2023 09:42 Inactive
@danielroe danielroe changed the title feat(app): improve client-side performance by prefetching middleware … feat(nuxt): prefetch middleware/layouts + await layout loading Jan 19, 2023
@danielroe danielroe merged commit 912eafb into main Jan 19, 2023
@danielroe danielroe deleted the feat/perfs branch January 19, 2023 13:01
@Luffyyy
Copy link

Luffyyy commented Jan 19, 2023

I don't know if it's related, but this looks similar nuxt/nuxt#14860 just with nested routes instead of layouts and it's been like this for a while. Could you check if this pull fixes it or address it in general?

@danielroe
Copy link
Member

Testing on edge would be very welcome @Luffyyy πŸ™

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants